package com.eurekaclient.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.spring4all.swagger.EnableSwagger2Doc;

@EnableSwagger2Doc
@RestController
class ServiceInstanceRestController {

	@Autowired
	private DiscoveryClient discoveryClient;

	@Value("${author}")
	private String author;

	@RequestMapping(value = "/get-service-name/{applicationName}",method = RequestMethod.GET)
	public List<ServiceInstance> serviceInstancesByApplicationName(
			@PathVariable("applicationName") String applicationName) {
		return this.discoveryClient.getInstances(applicationName);
	}

	@Value("${server.port}")
	String port;

	@RequestMapping(value = "/hi",method = RequestMethod.GET)
	public String home(@RequestParam String name) {
		return author + " say: " + "Hi " + name + ",i am from port:" + port;
	}
	// 输入localhost:8011/xxxx/eurekaclient 试试
	

}